/**
 * Copyright (C) 2021 UnionTech Software Technology Co., Ltd. All rights reserved.
 * @author 陈弘唯
 * @Email  : chenhongwei@uniontech.com
 * @date 2021/11/19 上午10:28
 */

package pkg

import (
	"fmt"
)

type UbxErr struct {
	Handler string
	Msg     string
}

func (e *UbxErr) Error() string {
	return fmt.Sprintf("Func:[%s] happen Err:[%v]", e.Handler, e.Msg)
}

func (e *UbxErr) Attach(msg interface{}) *UbxErr {
	switch msg.(type) {
	case string:
		return &UbxErr{
			Msg: e.Msg + msg.(string),
		}
	default:
		return &UbxErr{
			Msg: e.Msg + fmt.Sprintf(" Value is [%+v]", msg),
		}
	}
}

func New(handler, msg string) *UbxErr {
	return &UbxErr{
		Handler: handler,
		Msg:     msg,
	}
}
